/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "RigidTerrain.h"
#include "TerrainManager.h"

namespace PQEngine
{
	RigidTerrain::RigidTerrain(TerrainObject* object)
	{
		int heightStickWidth=TerrainManager::TERRAIN_SIZE;
		int heightStickLength=TerrainManager::TERRAIN_SIZE;
		float heightScale=1;
		float minHeight=object->getMinHeight();
		float maxHeight=object->getMaxHeight();
		float scaleX=TerrainManager::TERRAIN_SCALE;
		float scaleZ=TerrainManager::TERRAIN_SCALE;
		btVector3 scale(scaleX,1,scaleZ);
		
		_shape=new btHeightfieldTerrainShape(heightStickWidth,heightStickLength,
			object->getHeightData(),heightScale,minHeight,maxHeight,1,PHY_FLOAT,true);
		_shape->setUseDiamondSubdivision(true);
		_shape->setLocalScaling(scale);

		_rigidBody = new btRigidBody(0.0, 0, _shape);
		_rigidBody->setRestitution(object->getRestitution());
		_rigidBody->setFriction(object->getFriction());

		Ogre::Vector3 position=object->getWorldPosition();
		Ogre::AxisAlignedBox box=object->getWorldAABB();

		_rigidBody->getWorldTransform().setOrigin(btVector3(position.x,position.y,position.z));
        _rigidBody->getWorldTransform().setRotation(btQuaternion());
	}

}
